'use client'

import './globals.css'
import Sidebar from '@/app/components/Sidebar'
import Header from '@/app/components/Header'
import { Toaster } from 'sonner'
import { usePathname } from 'next/navigation'

// 创建一个客户端组件来处理布局
function ClientLayout({ children }: { children: React.ReactNode }) {
  const pathname = usePathname()
  const isLoginPage = pathname === '/login'

  if (isLoginPage) {
    return children
  }

  return (
    <div className="flex h-screen">
      <Sidebar />
      <div className="flex-1 flex flex-col">
        <Header />
        <main className="flex-1 overflow-y-auto">
          {children}
        </main>
      </div>
    </div>
  )
}

// 根布局组件
export default function RootLayout({
  children,
}: {
  children: React.ReactNode
}) {
  return (
    <html lang="zh">
      <body>
        <Toaster richColors position="top-center" />
        <ClientLayout>
          {children}
        </ClientLayout>
      </body>
    </html>
  )
}

